from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `zhan_email_code` ADD `email_type` INT NOT NULL  COMMENT '邮件类型' DEFAULT 1;
        CREATE TABLE IF NOT EXISTS `zhan_token` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `token` LONGTEXT NOT NULL  COMMENT 'token',
    `user_id` INT NOT NULL,
    CONSTRAINT `fk_zhan_tok_zhan_use_4b9cd689` FOREIGN KEY (`user_id`) REFERENCES `zhan_user` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE `zhan_email_code` DROP COLUMN `email_type`;
        DROP TABLE IF EXISTS `zhan_token`;"""
